// vite.config.ts
import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {NaiveUiResolver} from 'unplugin-vue-components/resolvers'
import VueJsx from '@vitejs/plugin-vue-jsx'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
    base: '/admin',
    build: {
        outDir: 'admin'
    },
    plugins: [
        VueJsx(),
        vue(),
        AutoImport({
            dts: true,
            imports: [
                'vue', 'vue-router',
                {
                    'naive-ui': [
                        'useDialog',
                        'useMessage',
                        'useNotification',
                        'useLoadingBar'
                    ]
                }
            ]
        }),
        Components({
            dirs: ['src/components'],
            dts: true,
            resolvers: [NaiveUiResolver()]
        })
    ],
    resolve: {
        alias: {
            '@': path.resolve(__dirname, "src"),
            '@pages': path.resolve(__dirname, "src/pages"),
            '@api': path.resolve(__dirname, "src/api"),
        }
    },
    server: {
        proxy: {
            '/api': {
                target: 'http://localhost',
                changeOrigin: true,
                rewrite: path => path.replace(/^\/api/, '')
            },
            '/img': {
                target: 'http://localhost',
                changeOrigin: true,
            }
        }
    }
})